<?
	include ("./include.php");
?>
<br/>
<table style="width:1000px;height:50px;border:5px #CCCCCC solid;">
    <tr>
        <td align="center" valign="middle" style="font-zise:15px;font-weight:bold;">글목록</td>
    </tr>
</table>
<br/>
<table cellspacing="1" style="width:1000px;height:50px;border:0px;background-color:#999999;">
    <tr>
        <td align="center" valign="middle" width="5%" style="height:30px;background-color:#CCCCCC;">번호</td>
        <td align="center" valign="middle" width="60%" style="height:30px;background-color:#CCCCCC;">글제목</td>
        <td align="center" valign="middle" width="15%" style="height:30px;background-color:#CCCCCC;">글쓴이</td>
        <td align="center" valign="middle" width="20%" style="height:30px;background-color:#CCCCCC;">작성일</td>
    </tr>
<?

	if($_GET[page] && $_GET[page] > 0){
	    $page = $_GET[page];
	}else{
	    $page = 1;
	}
	$page_row = 10;
	$page_scale = 10;
	$paging_str = "";
	
	$sql = "select count(*) as cnt from tb_board where 1";
	$total_count = sql_total($sql);
	
	$paging_str = paging($page, $page_row, $page_scale, $total_count);
	
	$from_record = ($page - 1) * $page_row;
	
	$query = "select * from tb_board where 1 order by b_num desc, b_reply asc limit ".$from_record.", ".$page_row;
	$result = mysql_query($query, $connect);
	
	$i = 0;
	
	while($data = mysql_fetch_array($result)){
	
	    $reply_str = "";
	    $reply_depth = strlen($data[b_reply]);
	    if ($reply_depth > 0){
	        for ($k=0; $k<$reply_depth; $k++){
	            $reply_str .= '&nbsp;&nbsp;&nbsp;';
	        }
	        $reply_str .= '▷(Re)';
	    }
	
	?>
	    <tr>
	        <td align="center" valign="middle" style="height:30px;background-color:#FFFFFF;"><?=($total_count - (($page - 1) * $page_row) - $i )?></td>
	        <td align="center" valign="middle" style="height:30px;background-color:#FFFFFF;"><?=$reply_str?><a href="./board_view.php?b_idx=<?=$data[b_idx]?>&page=<?=$page?>"><?=$data[b_title]?></a></td>
	        <td align="center" valign="middle" style="height:30px;background-color:#FFFFFF;"><?=$data[m_id]?></td>
	        <td align="center" valign="middle" style="height:30px;background-color:#FFFFFF;"><?=substr($data[b_regdate],0,10)?></td>
	    </tr>
	<?
	    $i++;
	}
	
	if($i == 0){
	?>
	    <tr>
	        <td align="center" valign="middle" colspan="4" style="height:50px;background-color:#FFFFFF;">현재 게시물이 없습니다</td>
	    </tr>
	<?
	}
	?>
	</table>
	<br/>
	<table style="width:1000px;height:50px;">
	    <tr>
	        <td align="center" valign="middle"><?=$paging_str?></td>
	    </tr>
	    <?if($_SESSION[user_id]){?>
	    <tr>
	        <td align="center" valign="middle"><input type="button" value=" 글쓰기 " onClick="location.href='./board_write.php';"></td>
	    </tr>
	    <?}?>
	</table>